package com.bailan.foreat.mapper;

import com.bailan.foreat.entity.Comment;
import com.bailan.foreat.vo.CommentVo;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author ste
 * @since 2023-02-21 07:50:43
 */
@Mapper
public interface CommentMapper extends BaseMapper<Comment> {

    @Select("select tc.content,tc.grade,tc.create_time createTime,\n" +
            "tu.username,tu.user_img userImg,\n" +
            "tp.product_name productName \n" +
            "from t_comment tc INNER JOIN t_user tu inner JOIN t_product tp\n" +
            "on tc.user_id=tu.id and tc.product_id=tp.id\n" +
            "where product_id=#{productId} \n" +
            "ORDER BY create_time desc")
    IPage<CommentVo> selectByProductId(Page page, Integer productId);
}
